<?php
require('init.php');

$scid = (int)$_GET['id'];

/*$source = $DB->q('MAYBETUPLE SELECT * FROM solution_sc
                  WHERE sscid = %i',$id);*/

$source = get_source('1', '', $scid, $conn_db2);
//print_r($source);
$source =$source[1];

if ( empty($source) ) error ("Submission $scid not found");

$sourcefile = getSourceFilename($source['cid'],$id,$source['teamid'],
	$source['probid'],$source['langid']);
// Download was requested
if ( isset($_GET['fetch']) ){
	header("Content-Type: text/plain; name=\"$sourcefile\"; charset=" . DJ_CHARACTER_SET);
	header("Content-Disposition: inline; filename=\"$sourcefile\"");
	header("Content-Length: " . strlen($source['sourcecode']));

	echo $source['sourcecode'];
	exit;
}
